package org.eproject.core.well.command;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.eproject.core.well.delegate.UserDeleGate;
import org.eproject.core.well.exception.CommandException;
import org.eproject.core.well.exception.DeleGateException;
import org.eproject.core.well.exception.FactoryException;
import org.eproject.core.well.factory.Simplefactory;
import org.eproject.core.well.viewhelp.Helper;

public class Hgrantcommand implements ICommand{

	public String execute(Helper h) throws CommandException {
		String modulepk = (String)h.getData().get("modulepk");
		String modulepath = (String)h.getData().get("modulepath");
		HttpSession session = h.getReq().getSession();
		Map userinfo = (Map)session.getAttribute("userinfo");
		int uid = Integer.valueOf(userinfo.get("uid").toString());
		List lh = null;
		try {
			UserDeleGate ud = (UserDeleGate)Simplefactory.creatorBean("userdelegate");
			lh = ud.getShandle(uid,Integer.valueOf(modulepk));
			session.setAttribute("handle",lh);
			return modulepath;
		} catch (FactoryException e) {
			e.printStackTrace();
			throw new CommandException(e);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			throw new CommandException(e);
		} catch (DeleGateException e) {
			e.printStackTrace();
			throw new CommandException(e);
		}
	}

}
